const app = getApp();

Component({
  properties: {
    link: {
      type: String,
      value: ''
    }
  },
  options: {
    addGlobalClass: true
  },
  data: {
    active: '/pages/index/index'
  },
  ready() {
    if (app.global.tabbar) {
      const {
        color,
        color_active,
        background,
        item
      } = app.global.tabbar
      
      item.forEach((item, index) => {
        if (item.link == this.properties.link) {
          this.setData({ active: index })
        }
      })
      this.setData({
        color: color,
        color_active: color_active,
        background: background,
        item: item
      });
    }
  },
  methods: {
    click(event) {
      this.setData({ active: event.detail });
    },

    redirect(event) {
      if (event.currentTarget.dataset.link) {
        // wx.switchTab({
        //   url: event.currentTarget.dataset.link
        // })
        wx.navigateTo({
          url: event.currentTarget.dataset.link
        })
      }
    }
  }
})